﻿<%@ Page Language="C#" %>

<%@ Import Namespace="IRL.Utilities" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>


<script runat="server">
    public const int CURRENT_MODULE = 51;
    
    int pid, yearQry; 
    int proposalID, forYear;
    object projectType, researchCategory, researchType;
    string projectName, clientName, projectCode, researchMethodologies, operationalSector;    
    
    protected void Page_Load(object src, EventArgs e)
    {
        Security SysAcc = new Security(CURRENT_MODULE);
        // check is authenticate
        SysAcc.Authenticate();
        
        // load reminder count
        //Mics.loadReminderCount(lblReminderCount);

        if (Request.QueryString["year"] != null)
            yearQry = Convert.ToInt32(Request.QueryString["year"]);
        if (Request.QueryString["pid"] != null)
        {
            pid = Convert.ToInt32(Request.QueryString["pid"]);
            loadSelector();
            if (!Page.IsPostBack)
            {
                rebind();
                //renderPager();
            }
        }
    }

    void loadSelector()
    {
        int currentYear = DateTime.Today.Year;
        int selectedYear;
        string strNewer, strOlder;

        if (yearQry == 0)
            selectedYear = currentYear - 1;
        else
            selectedYear = yearQry;

        yearQry = selectedYear;
        strOlder = "<a href='?pid=" + pid + "&year=" + (selectedYear - 1) + "'>&lt;Older</a>";
        strNewer = "<a href='?pid=" + pid + "&year=" + (selectedYear + 1) + "'>Newer&gt;</a>";
        if (selectedYear >= currentYear - 1)
        {
            strNewer = "<span class='disabled'>Newer&gt;</span>";
        }

        // set value
        SelectedYear.Text = "<span class='selected'>" + selectedYear.ToString() + "</span>";
        NewerYear.Text = strNewer;
        OlderYear.Text = strOlder;
        
        // load projects
        rebind_Projects();
    }

    private void rebind_Projects()
    {
        object connStr = ConfigurationSettings.AppSettings["sqlConn"];
        using (SqlConnection conn = new SqlConnection(connStr.ToString()))
        {
            SqlCommand cmd = new SqlCommand("SELECT [ProposalID], [ProjectName] FROM vw_ArchivedProjects WHERE [ForYear]=" + yearQry, conn);
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            // bind to control
            repProjects.DataSource = dr;
            repProjects.DataBind();
        }
    }

    protected string showProject(int proposalID, string projectName)
    {
        if (proposalID == pid)
        {
            return "<span class='selected'>" + projectName + "</span>";
        }
        else
        {
            return "<a href='?pid=" + proposalID + "&year=" + yearQry + "'>" + projectName + "</a>";
        }
    }
    
    void rebind()
    {
        object connStr =  ConfigurationSettings.AppSettings["sqlConn"];
        using(SqlConnection conn = new SqlConnection(connStr.ToString()))
        {
            SqlCommand cmd = new SqlCommand("sp_ProjectDetail", conn);
            SqlDataReader dr;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@proposalid", SqlDbType.Int).Value = pid;
            
            conn.Open();
            dr = cmd.ExecuteReader();            
            // assign project info to variables
            if (dr.Read())
            {
                proposalID = dr.GetInt32(dr.GetOrdinal("ProposalID"));
                forYear = dr.GetInt16(dr.GetOrdinal("ForYear"));
                projectName = dr["ProjectName"].ToString();
                clientName = dr["ClientName"].ToString();
                projectCode = dr["ProjectCode"].ToString();
                //operationalSector = dr.GetInt32(dr.GetOrdinal("Sector"));
                operationalSector = dr["Sector"].ToString();
                projectType = dr.GetInt32(dr.GetOrdinal("ProjectType"));
                researchCategory = dr.GetInt32(dr.GetOrdinal("ResearchCategory"));
                researchType = dr.GetInt32(dr.GetOrdinal("ResearchType"));
                researchMethodologies = dr["ResearchMethodology"].ToString();
                // Get Lookup value
                dr.Close();
                //operationalSector = Lookup.GetText("sp_Select_cms_Lookup 'client_type', " + operationalSector.ToString() + ", 1", conn);
                projectType = Lookup.GetText("sp_Select_cms_Lookup 'project_type', " + projectType.ToString() + ", 1", conn);
                researchCategory = Lookup.GetText("sp_Select_cms_Lookup 'research_category', " + researchCategory.ToString() + ", 1", conn);
                researchType = Lookup.GetText("sp_Select_cms_Lookup 'research_type', " + researchType + ", 1", conn);
                
            }
            else
            {
                Response.Redirect("listArchivedProjects.aspx");
            }
            // list Associated files
            
            SqlCommand cmdFiles = new SqlCommand("SELECT * FROM [cms_Files] WHERE [ProposalID]=" + proposalID, conn);
            dr = cmdFiles.ExecuteReader();
            repFiles.DataSource = dr;
            repFiles.DataBind();            
            
            // close connection
            conn.Close();
        }
    }

    // trim filename
    protected string TrimFilename(string Filename)
    {
        int MaxLength = 45;
        if (Filename.Length > MaxLength)
        {            
            return ("..."+Filename.Substring(MaxLength));
        }
        else
        {
            return Filename;
        }
    }
        
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="Description" content="Providing the tools and expertise needed to navigate in the emerging consumer markets of Indochina.">
    <meta name="keywords" content="Research in Indochina, Research Consultants in Indochina, Marketing Research in Indochina, Marketing Research Companies in Indochina, Marketing Consultants in Indochina Research in Vietnam, Research Consultants in Vietnam, Marketing Research in Vietnam, Marketing Research Companies in Vietnam, Marketing Consultants in Vietnam Research in Cambodia, Research Consultants in Cambodia, Marketing Research in Cambodia, Marketing Research Companies in Cambodia, Marketing Consultants in Cambodia Research in Laos, Research Consultants in Laos, Marketing Research in Laos, Marketing Research Companies in Laos, Marketing Consultants in Laos">
    <meta name="robots" content="all">

    <title>Indochina Research</title>
    <link href="../css/global.css" rel="stylesheet" type="text/css" />
    <link href="css/cms.css" rel="stylesheet" type="text/css" />
    
        
</head>
<body>
<table width="773" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td width="765" height="540" align="center" valign="top" style="border:solid 1px #10147e;" >
			<!-- header -->
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr bgcolor="#F4F4F9">
					<td colspan="3" align="right" style="padding:10px;">
						<b class="blueL">Client Management System</b>
					</td>
				</tr>
				<tr>
					<td class="wave_l">&nbsp;</td>
					<td><img src="images/wave_logo.jpg" width="107" height="83"></td>
					<td class="wave_r">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="3" style="padding:0 20px;">
						<div style="background-color:#bcb3d5; padding:5px 10px;">
							<span style="float:right">
							    <a class="blue" href="javascript:history.go(-1);">&laquo; Back</a>
							</span>
							<span class="pathmap">
								<a href="default.aspx" >CPanel</a> :: 
								<a href="default2.aspx" >Ops Files</a> :: 
								<a href="historical_Projects.aspx">Historical Data</a> :: 
								Project Details
						  </span>
						</div>
						<br />
						
						
					</td>
				</tr>
				
			</table>
			
			<!-- body -->
			<form id="DataForm" method="post" runat="server">
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td align="left" valign="top" style="padding:0 20px;">
						<table border="0" >
                            <tr>
                                <td valign="top">
                                    <table class="p_selector" width="200" border="0">
                                        <tr>
                                            <td rowspan="5" width="5">
                                                <img src="images/spacer.gif" width="5" height="1" /></td>
                                            <td colspan="3" height="5">
                                                <img height="5" src="images/spacer.gif" width="1" /></td>
                                            <td rowspan="5" width="5">
                                                <img height="1" src="images/spacer.gif" width="5" /></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Literal ID="OlderYear" runat="server" /></td>
                                            <td align="center">
                                                <asp:Literal ID="SelectedYear" runat="server" />
                                            </td>
                                            <td align="right">
                                                <asp:Literal ID="NewerYear" runat="server" /></td>
                                        </tr>
                                        <tr height="10">
                                            <td colspan="3" align="center">
                                                <img src="images/sep.gif" width="96%" height="3" /></td>
                                        </tr>
                                        <tr>
                                            <td colspan="3" valign="top" height="120">
                                                <asp:Repeater ID="repProjects" runat="server">
                                                    <ItemTemplate>
                                                        <%#showProject((int)DataBinder.Eval(Container.DataItem, "ProposalID"), DataBinder.Eval(Container.DataItem, "ProjectName").ToString())%>
                                                    </ItemTemplate>
                                                    <SeparatorTemplate>
                                                        ,
                                                    </SeparatorTemplate>
                                                </asp:Repeater>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="3" height="5">
                                                <img src="images/spacer.gif" width="1" height="5" /></td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="10" valign="top">
                                    <img class="lip" src="images/lip.gif" />
                                </td>
                                <td valign="top">
                                    <table border="0" width="497" align="left" cellspacing="0" cellpadding="6">
                                        <tr>
                                            <td width="100" align="right">Year:</td>
                                            <td class="blueL"><%=forYear %></td>
                                            <td width="20">&nbsp;</td>
                                            <td width="100" align="right">&nbsp;</td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td align="right">Client name:</td>
                                            <td colspan="4" class="blueL"><%=clientName %></td>
                                        </tr>
                                        <tr>
                                            <td align="right">Project name:</td>
                                            <td colspan="4" class="blueL"><%=projectName %></td>
                                        </tr>
                                        
                                        <tr>
                                            <td align="right">Code:</td>
                                            <td class="blueL"><%=projectCode %></td>
                                            <td>&nbsp;</td>
                                            <td align="right">Sector:</td>
                                            <td class="blueL"><%=operationalSector %></td>
                                        </tr>
                                        <tr>
                                            <td align="right">Type:</td>
                                            <td class="blueL"><%=projectType.ToString() %></td>
                                            <td>&nbsp;</td>
                                            <td align="right">Category:</td>
                                            <td class="blueL"><%=researchCategory.ToString() %></td>
                                        </tr>
                                        <tr>
                                            <td align="right">Research type:</td>
                                            <td colspan="4" class="blueL"><%=researchType.ToString() %></td>
                                        </tr>
                                        <tr>
                                            <td align="right">Methodologies:</td>
                                            <td colspan="4" class="blueL"><%=researchMethodologies %></td>
                                        </tr>
                                        <tr>
                                            <td valign="top" align="right">
                                                Associated files:
                                            </td>
                                            <td colspan="4" class="blueL">
                                                <asp:Repeater ID="repFiles" runat="server">
                                                    <ItemTemplate>
                                                        <div>
                                                            <a href="download.aspx?pid=<%#proposalID %>&filename=<%# Server.UrlEncode(DataBinder.Eval(Container.DataItem, "Filename").ToString()) %>&salt=<%# DataBinder.Eval(Container.DataItem, "Ticks").ToString() %>"
                                                                title="Download">
                                                                <%# TrimFilename(DataBinder.Eval(Container.DataItem, "Filename").ToString())%>
                                                            </a>
                                                        </div>
                                                    </ItemTemplate>
                                                    <SeparatorTemplate>
                                                        &nbsp;
                                                    </SeparatorTemplate>
                                                </asp:Repeater>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
					</td>
				</tr>
			</table>
			</form>
			
		</td>
		
		<td width="6" class="rightShadow" valign="top">
			<img src="images/white.gif" width="6" height="6" /></td>
	</tr>
	
	<!-- bottom shadow -->
	<tr>
		<td height="6" class="bottomShadow">
			<img src="images/white.gif" width="6" height="6" /></td>
		
		<td width="6" height="6">
			<img src="images/shadow_corner.gif" width="6" height="6" /></td>
	</tr>
</table>


</body>
</html>
